define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/register/personInfos/personSupport",
						"AppPathDir/register/personInfos/addSupport",
						"AppPathDir/register/personInfos/updateSupport",
						"PDUtilDir/util", "PDUtilDir/tool",
						"PDUtilDir/slidebar", "PDUtilDir/inputSelect","Date",
						"DateCN", "css!DateCss" ],
				function(Support, AddSupport, UpdateSupport, Util, Tool,
						Slidebar, inputSelect) {
					/* 查询 start */
					$scope.cache = {
						types : new Array(),
						roles : new Array(),
						teams : new Array(),
						projects : new Array(),
						workerType : new Array(),
						typeMap: new Map(),
						workerTypeMap:new Map(),
						rolesMap:new Map(),
						projectsMap:new Map(),
						teamMaps : new Map(),
						certificates : new Array()
					};
					$scope.entity = {
							projectCode : '',
							projectCodes:'',
							
							
						};
			
					$scope.search = {
							name : "",
							personNo : "",
							projectCode : "",
							team:"",
					}
					$scope.searchSupport = {
							
						run : function() {
							$scope.grid.reload({
								queryParam : {
									name : $scope.search.name,
									personNo : $scope.search.personNo,
									projectCode : $scope.search.projectCode,
									team : $scope.search.team,
								}
							})
						}
					
					};
					/* 查询 end */
//					$scope.addSupport = AddSupport($scope, $compile);
					$scope.updateSupport = UpdateSupport($scope, $compile);

					$scope.delSupport = {
						run : function() {
					
							var selectRows = $scope.grid.getSelectedRow();
							if (null != selectRows && selectRows.length>0) {
								Util.confirm("是否要删除", function() {
									debugger;
									var ids = new Array();
									$.each(selectRows, function(index, selectRow) {
										ids.push(selectRow.id);
									});
									$.ajax({
										url : getServer()
												+ "/flea/hclv/person/deleteByIds.htmls",
										method : 'post',
										data : {
											'ids' : JSON.stringify(ids)
										},
										success : function(data) {
											$scope.grid.refresh();
											Util.alert(data.message);
										}
									});

								});
							} else {
								Util.alert('请选择要删除的数据！');
							}
						}
					};
/*					
					types : new Array(),
					roles : new Array(),
					projects : new Array(),
					workerType : new Array(),
					typeMap: new Map(),
					workerTypeMap:new Map(),
					rolesMap:new Map(),
					projectsMap:new Map(),
					certificates : new Array()*/
					$scope.gridRender = function() {
						if($scope.cache.projects.length > 0){
							$scope.grid = Support.init($scope.cache, $scope.addSupport,
									$scope.updateSupport, $scope.delSupport,
									$scope.searchSupport);
						}
					};
					
					var init = function() {
//						$.ajax({
//							url : getServer() + "/flea/hclv/getCertificates.htmls",
//							success : function(data) {
//								$scope.cache.certificates = data.data;
						/*		$scope.gridRender();*/
								// 证件类型
//								inputSelect.dropCache();
//								inputSelect({
//									id : "queryType",
//									key : {
//										id : "dictCode",
//										name : "dictName",
//										data : "data",
//									},
//									data : $scope.cache.certificates,
//									simpleData : true,
//									// 启用文本搜索
//									// initData:[initProvice],
//									searchAble : false,
//									callback : function(id) {
//										$scope.search.type = id[0];
//									}
//								});
//							}
//						});
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getDictWorkType.htmls",
							success : function(data) {
								$scope.cache.workerType = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.workerTypeMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						$.ajax({
							url : getServer() + "/flea/hclv/getUserBD.htmls",
							success : function(data) {
								$scope.cache.bdType = data.data;
								if(data.data=="BD000"){
									$("#bd").show();
								}
								
								
								$scope.gridRender();
							}
						});
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getFaceRoleType.htmls",
							success : function(data) {
								$scope.cache.roles = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.rolesMap.set(row.dictCode, row.dictName);
								});
//								$scope.gridRender();
							}
						});
						$.ajax({
							url : getServer() + "/flea/hclv/getTeams.htmls",
							success : function(data) {
								$scope.cache.teams = data.data;
							
								$.each(data.data, function(index, row) {
									$scope.cache.teamMaps.set(row.dictCode, row.dictName);
								});
								inputSelect.dropCache();
								inputSelect({
									id : "teamName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : $scope.cache.teams,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.team = id[0];
										$scope.search.teamName = id[1];
									}
								});
							}
						});
						
						
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getDictHTProject.htmls",
							success : function(data) {
								$scope.cache.projects = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.projectsMap.set(row.dictCode, row.dictName);
								});
								$scope.gridRender();
								
								inputSelect.dropCache();
								inputSelect({
									id : "projectName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : $scope.cache.projects,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.projectCode = id[0];
										$scope.search.projectName = id[1];
									}
								});
								
								
								
							}
						});
						setTimeout($scope.gridRender(),3000 ); 
					
					}
					init();
				})
	}
});